<!-- 粉丝页面： ty -->

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="/chat/css/mall.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/chat/font_Icon/iconfont.css">
    <link rel="stylesheet" type="text/css" href="/chat/css/chat.css">
	<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
	<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
	<script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

</head>
<body>

<div class="chatContainer">
      
    <div  class="chatBox" ref="chatBox">
    
     <div id="child_header" style="width:100%;height:50px">
        <div class="goback"><a href="javascript:history.back(-1)"><i></i></a></div>
        <div class="current_location"><span>粉丝列表</span></div>
    </div>
		
        <div class="chatBox-info">
						
            <div class="chatBox-list" ref="chatBoxlist">
				
             
                <!-- 好友列表 -->
             
             
                        
               
            </div>
</div>



        </div>
    </div>
</div>
<input type="hidden" id="myid" >


<!-- 模态框（Modal） :  私信     -->
<div class="modal fade" id="sendmessage" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					私信
				</h4>
			</div>
			<div class="modal-body">
				<textarea rows="3" cols="50" id="content">
				</textarea>				
				<button id="fasong" onclick="publishMessage()">Send</button>
			</div>
			
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
	

<script type="text/javascript" src="https://cdn-hangzhou.goeasy.io/goeasy.js"></script>           <!--  // 私信 -->
  <script type="text/javascript">      	 
	
//加载粉丝列表
$(function () {
	 flushFans(); });
	 
	 function flushFans(){
	 $.ajax({
         url:"/chat/fansList",
         async:false,
		  success: function (data) {		  
			  var context="";
	
			  for (var i = 0; i < data.length; i++) {				
				 var fan =  data[i];

				 context+= '<div class="chat-list-people">'
	               +'<div><a href="/chat/someoneinfo?uid='+fan.user_id+'"><img src="'+fan.user_headimg+'" alt="头像" /></a></div>'
	              +' <div class="chat-name">'
	              +'     <p>'+fan.user_name+'</p></div>'	
	              + '<input type="hidden"  id = "fanid"  value="'+fan.user_id+'"/>'
	              + '<input type="hidden"  id = "myname"  value="'+fan.myname+'"/>'

	              +' <div class="message-num" data-toggle="modal" data-target="#sendmessage" onclick="message('+fan.user_name+')">私信</div>'
	              +' <div class="message-num" onclick="follow('+fan.user_id+","+fan.followed_id+')"style="background-color:blue">+关注</div></div>'
	              
			}
 				$(".chatBox-list").html(context);
 						
		 	 }
		  });
	 }	 


  
  
  function follow(fanId,userId){       // 关注粉丝   -----变为好友

		$.ajax({
	          url:"/chat/addFirend",
	          data:{
	        	  "fanId":fanId,
	        	  "userId":userId
	          },
			  success: function (data) {
				  flushFans();
			  }
		 });
	}
	
    
    
    
    
  var goeasy = new GoEasy({
       appkey: 'BC-372aceece223476f86fe396ab9676c1c'
   });

  
 // var url = document.location.toString();//获取url地址
 // var urlParmStr = url.slice(url.indexOf('?')+4); //获取问号后所有的字符串 
  
 
/*    goeasy.subscribe({	  
       channel: document.location.toString().slice(url.indexOf('?')+4),         // +++++++++++改为当前登录用户名
       onMessage: function (message) {
           //收到消息的第一行，打出日志，以这个时间作为检查的标准
           alert('收到：' + message.content);
       }
   }); 
   */
  
       
 
        function publishMessage() {
            var publishMessage ="关注者>"+document.getElementById("myname").value+
            ":"+ document.getElementById("content").value;
            var channelname = document.getElementById("fanid").value;
            goeasy.publish({
                channel: channelname,        // +++++++++++改为当前登录用户名
                message: publishMessage,
                onFailed: function (error) {
                    alert(error.code + " : " + error.content);
                },
                onSuccess: function () {
                    document.getElementById("content").value = '';
 
                }
            });            
           
        }


    </script>
    




</body>
</html>
